package com.auto.api.core.type.json.yapi;

import com.auto.api.common.utils.JsonMapper;
import com.auto.api.core.constants.MappingConstants;
import com.auto.api.core.util.BeanUtil;
import java.util.Map;
import org.springframework.core.ResolvableType;

/**
 * @program:
 * @description: ObjectApiResultJsonTypeHandler类型处理器
 * @author: liangshf
 * @create: 2020-09-24
 */
public class ObjectApiResultJsonTypeHandler extends AbstractApiResultJsonTypeHandler {

    @Override
    public boolean canCovert(ResolvableType resolvableType) {
        return resolvableType.resolve().getSimpleName().equals(MappingConstants.OBJECT);
    }

    @Override
    public String getResultJson(ResolvableType resolvableType, Map root) {
        root.putAll(BeanUtil.getProperties(resolvableType.resolve().getSimpleName(), MappingConstants.EMPTY_STRING));
        return JsonMapper.toJson(root);
    }
}